<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>父子组件之间的信息传递</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="root">
        <counter :count="0" @changenum="handleChange"></counter>
        <counter :count="4" @changenum="handleChange"></counter>
        <div >{{total}}</div>
    </div>
    <script>
        // 局部组件
        var counter = {
            props:['count'],
            data: function(){
              return {
                  number: this.count
              }
            },
            template: "<div @click='handleClick'>{{number}}</div>",
            methods: {
                handleClick: function () {
                    //this.number ++;
                    //this.$emit("changenum", 1)
                     this.number = this.number + 2;
                    this.$emit("changenum", 2)

                }
            }
        }
        var vm = new Vue({
            el: "#root",
            data: {
              total: 4
            },
            components: {
                counter
            },
            methods: {
                handleChange: function (step) {
                    this.total += step
                }
            }
        });
    </script>
</body>
</html>